package cpa.prowon.gui.actions;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;

import pho.prowon.category.RootIndexCategory;
import cpa.prowon.Application;
import cpa.prowon.gui.MainWindow;
import cpa.prowon.image.ImageContainer;

/**
 * The delete action is used to delete a physical file or multiple behind images
 * @author Chris
 */
public class DeleteAction extends RemoveAction {

	/**
	 * Constructor
	 * @param MainWindow The window where the action is used
	 * @author
	 */
	public DeleteAction(MainWindow w) {
		super(w);
	}

	/**
	 * Return the title key
	 * @return The title key
	 * @author Chris
	 */
	protected String getTitleKey() {
		return "menu_item_edit_delete";
	}

	/**
	 * Return the tooltip key
	 * @return The tootip key
	 * @author Chris
	 */
	protected String getTooltipKey() {
		return "menu_item_edit_delete_tooltip";
	}

	/**
	 * Return the image key
	 * @return The image key
	 * @author Chris
	 */
	protected String getImageKey() {
		return "file:icons/delete.gif";
	}

	/**
	 * Return title for the message box
	 * @return The message box title
	 * @author Chris
	 */
	protected String getMessageBoxTitle() {
		return Application.getInstance().getResourceBundle().getString("title_deleteimages");
	}

	/**
	 * Return message for the message box
	 * @return The message box message
	 * @author Chris
	 */
	protected String getMessageBoxMessage() {
		return Application.getInstance().getResourceBundle().getString("msg_deleteimages");
	}

	/**
	 * Do the actual removal of the image. In addition to the removal of the
	 * RemoveAction, also delete the file
	 * @param RootIndexCategory The root index category which is the current index
	 * @param ImageContainer The image to be removed
	 * @author Chris
	 */
	protected void removeImage(RootIndexCategory ic, ImageContainer image) {
		
		// Remove the physical file as well
		File file = new File(image.getPathName());
		boolean success = file.delete();
		if (success == false) {

			// Ask the user whether he is really sure to remove the selected image(s) the index
			MessageBox msgBox = new MessageBox(window.getShell(), SWT.OK);
			msgBox.setText(Application.getInstance().getResourceBundle().getString("title_cannot_delete_file"));
			msgBox.setMessage(Application.getInstance().getResourceBundle().getString("msg_cannot_delete_file"));
			msgBox.open();
		
		} else {

			super.removeImage(ic, image);

		}
		
	}

}
